package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.entity.sys.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;
    @Override
    public PageInfo<SysRole> listRoles(String roleName, Integer pageNum, Integer pageSize) {
        //启用分页查询
        PageHelper.startPage(pageNum,pageSize);
        //调用mapper条件查询
        List<SysRole> sysRoleList =  sysRoleMapper.selectByRoleName(roleName);
        //将mapper返回的结果封装为分页对象
        return new PageInfo<>(sysRoleList);
    }

    @Override
    public void deleteById(Long id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public void save(SysRole sysRole) {
        sysRoleMapper.save(sysRole);
    }

    @Override
    public SysRole getById(Long id) {
        return sysRoleMapper.getById(id);
    }

    @Override
    public void update(SysRole sysRole) {
        sysRoleMapper.update(sysRole);
    }

    @Override
    public List<SysRole> allRoles(Long userId) {
        return sysRoleMapper.selectRolesByUserId(userId);
    }
}
